<?php
namespace App\Repositories\Admin;

use App\Models\Admin\OrderCheckModel;
use App\Repositories\BaseRepository;

class OrderCheckRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new OrderCheckModel();
    }

    /**
     * 操作分页获取
     */
    public function getIndexList()
    {
        $models = $this->repository->orderBy('id','asc')
            ->paginate(10);
        $models->limit = 10;
        return $models;
    }

    public function setAdd($data)
    {
        $data['created_at'] = time();
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$id)
    {
        $data['updated_at'] = time();
        return $this->repository->where('id',$id)
            ->update($data);
    }

    public function getShowOne($id)
    {
        $model = $this->repository->where('id',$id)->first();
        if (!$model) { return ''; }
        $model->stylelists = ($model&&$model->stylelist) ?
            json_decode($model->stylelist,true) : '';
        $model->sizelists = ($model&&$model->sizelist) ?
            json_decode($model->sizelist,true) : '';
        $model->thrumlists = ($model&&$model->thrumlist) ?
            json_decode($model->thrumlist,true) : '';
        return $model;
    }

    public function getShowOneByOrder($orderId)
    {
        $model = $this->repository->where('order',$orderId)->first();
        if (!$model) { return ''; }
        $model->finishTime = $model->finishTime ? date('Y-m-d',$model->finishTime) : '';
        $model->stylelist = ($model&&$model->stylelist) ?
            json_decode($model->stylelist,true) : '';
        $model->sizelist = ($model&&$model->sizelist) ?
            json_decode($model->sizelist,true) : '';
        $model->thrumlist = ($model&&$model->thrumlist) ?
            json_decode($model->thrumlist,true) : '';
        return $model;
    }
}